home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / Documentation / Tech Notes & Articles / Recipes / Edit Menu / Info... recipes next >
Encoding:
Text File  |  1995-04-22  |  6.0 KB  |  268 lines  |  [TEXT/ttxt]

  1. OpenDoc™ Recipes
  2.  
  3.  
  4. Info… recipes
  5. By The OpenDoc Design Team
  6. January 1995
  7.  
  8.  
  9. © 1993-1995  Apple Computer, Inc. All Rights Reserved.
  10. Apple, the Apple logo, and Macintosh are registered trademarks of Apple Computer, Inc.
  11. Mac and OpenDoc are trademarks of Apple Computer, Inc. 
  12.  
  13.  
  14.  
  15. Introduction
  16.  
  17. One of the items in the OpenDoc “Edit” menu is “… Info…” which a user chooses if they want to get information about the selection like its name, kind, category, mod/creation dates, comments, etc.  This recipes serves as sample code to do this. 
  18.  
  19. Description
  20.  
  21. When an embedded part is selected, the active part should set the name of the “Info…” menu item to “Part Info…”, and selecting the command should bring up the PartFrameInfo dialog on that selected part.  When a link border is selected, the active part should set the name of the “Info…” menu item to “Link Info…”, and selecting the command should bring up the appropriate LinkInfo dialog.   If some native content is selected, and the active part supports an Info dialog of its own on that selected content, then it should set the name of the “Info…” menu item appropriately: “<mycontent> Info…” and display the appropriate dialog when the command is selected.  If there is no selection, the name of the “Info…” menu item should be set to “Part Info…” and the item disabled.
  22.  
  23. Changes since November, 1994
  24.  
  25. •  The recipe for handling the results of ShowLinkSourceInfo has changed slightly.  It is not necessary for the part to check for a change to the autoUpdate setting if infoAction.action is kODLinkInfoUpdateNow.  If the send updates setting is changed to automatic, the Update Now button is disabled.  If the send updates setting is changed to manual, the link should already be up to date.
  26.  
  27. Caveats
  28.  
  29. • This sample uses a private field fSelection which keeps track of the selection in a part specific manner.  For simplicity’s sake, we assume fSelection is an object which supports a few boolean methods regarding the nature of the selection.
  30.  
  31. • If the part editor does not support linking, then it can ignore the Link Info cases.
  32.  
  33. • If the part editor does support linking, the LinkBroken method notifies the selection that the content is no longer linked, the 
  34. UpdateSelectedLinks method causes source content to update a link and destination content to be replaced by the current link content, and the GetContentChangeID method returns the change id associated with the selected link content.
  35.  
  36. • If the part editor does not support embedding or linking, and does not support Info on any native content, then it should always set the menu item to "Part Info…" and disable it.
  37.  
  38. Sample
  39.  
  40. #ifndef SOM_ODInfo_xh
  41. #include <Info.xh>
  42. #endif
  43.  
  44. #ifndef SOM_ODSession_xh
  45. #include <ODSessn.xh>
  46. #endif
  47.  
  48. #ifndef SOM_ODArbitrator_xh
  49. #include <Arbitrat.xh>
  50. #endif
  51.  
  52. #ifndef SOM_ODMenuBar_xh
  53. #include <MenuBar.xh>
  54. #endif
  55.  
  56. #ifndef SOM_ODLink_xh
  57. #include <Link.xh>
  58. #endif
  59.  
  60. #ifndef SOM_ODLinkSource_xh
  61. #include <LinkSrc.xh>
  62. #endif
  63.  
  64.  
  65.  
  66. SOM_Scope void  SOMLINK XYZCompany_XYZPartAdjustMenus(
  67.         XYZCompany_XYZPart *somSelf, Environment *ev,
  68.         ODFrame* frame)
  69.  
  70. {
  71.  
  72.  
  73.     _fMenuBar->EnableCommand(ev, kODCommandGetPartInfo, kODTrue);
  74.  
  75.  
  76. }
  77.  
  78. SOM_Scope void  SOMLINK XYZCompany_XYZPartDoInfoCommand(
  79.         XYZCompany_XYZPart *somSelf, Environment *ev)
  80.  
  81. {
  82.  
  83. // called probably from this part's HandleEvent method tç
  84.     if  (fSelection->EmbeddedFrameSelected())
  85.  
  86.     {
  87.  
  88.         ODInfo* info = somSelf->GetStorageUnit(ev)
  89.  
  90.                                 ->GetSession(ev)
  91.  
  92.                                 ->GetInfo(ev);
  93.  
  94.         info->ShowPartFrameInfo(ev, _fSelection->GetFirstSelectedFacet(), fPermissions>=kDPSharedWrite);
  95.  
  96.     }
  97.  
  98. // Skip this else clause if your part editor does not support linking
  99.  
  100.     else if (_fSelection->LinkSourceBorderSelected())
  101.  
  102.     {
  103.  
  104.         ODLinkInfoResult     infoResult;
  105.  
  106.         ODLinkSource* linkSource = _fSelection->GetSelectedLinkSource();
  107.  
  108.         if ( linkSource->ShowLinkSourceInfo(ev, 
  109.  
  110.                                         _fSelection->GetFirstSelectedFacet(),
  111.  
  112.                                         _fSelection->GetContentChangeID(), fPermissions>=kDPSharedWrite,  
  113.  
  114.                                         &infoResult))
  115.  
  116.         {
  117.  
  118.             switch (infoResult.action) 
  119.  
  120.             {
  121.  
  122.             case kODLinkInfoBreakLink:
  123.  
  124.                 linkSource->SetSourcePart(ev, kODNULL);
  125.  
  126.                 linkSource->Release(ev);
  127.  
  128.                 _fSelection->LinkBroken();
  129.  
  130.                 somSelf->GetStorageUnit(ev)->GetDraft(ev)
  131.                     ->SetChangedFromPrev(ev);
  132.  
  133.                 break;
  134.  
  135.             case kODLinkInfoUpdateNow:
  136.  
  137.                 _fSelection->UpdateSelectedLink();
  138.  
  139.                 break;
  140.  
  141.             case kODLinkInfoOk:
  142.  
  143.                 if (infoResult.autoUpdate != linkSource->IsAutoUpdate(ev))
  144.  
  145.                 {
  146.  
  147.                     linkSource->SetAutoUpdate(ev, infoResult.autoUpdate);
  148.  
  149.                     if (infoResult.autoUpdate && 
  150.  
  151.                           (_fSelection->GetContentChangeID() != 
  152.  
  153.                                 linkSource->GetChangeID(ev))
  154.  
  155.                        )
  156.  
  157.                         _fSelection->UpdateSelectedLink();
  158.  
  159.                 }
  160.  
  161.                 break;
  162.  
  163.             default:
  164.  
  165.                 break;
  166.  
  167.             }
  168.  
  169.         }
  170.  
  171.     }
  172.  
  173. // Skip this else clause if your part editor do not support linking
  174.  
  175.     else if (_fSelection->LinkDestBorderSelected())
  176.  
  177.     {
  178.  
  179.         ODLinkInfoResult infoResult;
  180.  
  181.         ODLink* linkDest = _fSelection->GetSelectedLinkDest();
  182.  
  183.         ODLinkInfo* linkInfo = _fSelection->GetSelectedLinkInfo();
  184.  
  185.  
  186.         if (linkDest->ShowLinkDestinationInfo(ev, 
  187.  
  188.                                         _fSelection->GetFirstSelectedFacet(),
  189.  
  190.                                         linkInfo, fPermissions>=kDPSharedWrite, 
  191.  
  192.                                         &infoResult))
  193.  
  194.         {
  195.  
  196.             if (infoResult.action != kODLinkInfoBreakLink) 
  197.  
  198.                 if (infoResult.autoUpdate != linkInfo->autoUpdate)
  199.  
  200.                 {
  201.  
  202.                     linkInfo->autoUpdate = infoResult.autoUpdate;
  203.  
  204.                     if (infoResult.autoUpdate)
  205.  
  206.                     {
  207.  
  208.                         linkDest->RegisterDependent(ev, 
  209.                                                         _fPartWrapper, 
  210.  
  211.                                                         linkInfo->change);
  212.  
  213.                     }
  214.  
  215.                 }
  216.  
  217.  
  218.  
  219.             switch (infoResult.action) 
  220.  
  221.             {
  222.  
  223.             case kODLinkInfoFindSource:
  224.  
  225.                 linkDest->ShowSourceContent(ev);
  226.  
  227.                 break;
  228.  
  229.             case kODLinkInfoBreakLink:
  230.  
  231.                 // Only unregister if there are no more destinations of
  232.  
  233.                 //   this link in this part.
  234.  
  235.                 linkDest->UnregisterDependent(ev, _fPartWrapper);
  236.  
  237.                 linkDest->Release(ev);
  238.  
  239.                 _fSelection->LinkBroken();
  240.  
  241.                 somSelf->GetStorageUnit(ev)->GetDraft(ev)->
  242.  
  243.                     SetChangedFromPrev(ev);
  244.  
  245.                 break;
  246.  
  247.             case kODLinkInfoUpdateNow:
  248.  
  249.                 _fSelection->UpdateSelectedLink();
  250.  
  251.                 break;
  252.  
  253.             default:
  254.  
  255.                 break;
  256.  
  257.             }
  258.  
  259.         }
  260.  
  261.     }
  262.  
  263. }
  264.  
  265.